<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;

        }

        body,
        html {
            width: 100%;
            height: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .box {
            width: 600px;
            height: 600px;
            /* background-color: brown; */
        }

        div input {
            height: 40px;
            padding-left: 20px;
            border: 1px solid #ccc;
            border-radius: 5px;
            width: 100%;
            outline: none;
            box-sizing: border-box;
            margin-top: 30px;
        }

        p {
            float: right;
            margin-top: 10px;
            color: blue;
        }

        .blu {
            background-color: blue;
            color: #fff;
        }
    </style>
</head>

<body>
    <div class="box">
        <div>
            <input type="text" placeholder="手机号/用户名/邮箱">
        </div>
        <div>
            <input type="password" placeholder="密码">
        </div>
        <p>忘记密码?</p>
        <input type="button" value="登录" class="blu">
    </div>

</body>

</html>

<script src="./ajax.js"></script>
<script>
    var input = document.querySelectorAll('input')

    input[2].onclick = function () {
        if (input[0].value && input[1].value) {
            // if (/^1[3-9]\d{9}$/.test(input[0].value) && /^\d{4}$/.test(input[1].value)) {
                if(/^\d{4}$/.test(input[1].value)){
                ajax('get', 'https://yantianfeng.com/api/login', { username: input[0].value, password: input[1].value }, function (data) {
                    if (data.code == 200) {
                        console.log('登陆成功');
                    } else {
                        console.log('登陆失败！');
                    }
                })
            }else{
                alert('请输入正确的手机号/密码')
            }
        }else{
            alert('用户名/密码不能为空！')
        }
    }
</script>